<template>
  <div class="register-container">
    <div class="register-box">
      <div class="register-header">
        <h1 class="register-title">钢铁企业安全生产智能监管平台</h1>
        <p class="register-subtitle">用户注册</p>
      </div>
      
      <form @submit.prevent="handleRegister" class="register-form">
        <div class="form-group">
          <label for="username" class="form-label">用户名</label>
          <div class="input-wrapper">
            <i class="fas fa-user input-icon"></i>
            <input
              id="username"
              v-model="registerForm.username"
              type="text"
              class="form-input"
              placeholder="请输入用户名"
              required
            />
          </div>
        </div>
        
        <div class="form-group">
          <label for="email" class="form-label">邮箱</label>
          <div class="input-wrapper">
            <i class="fas fa-envelope input-icon"></i>
            <input
              id="email"
              v-model="registerForm.email"
              type="email"
              class="form-input"
              placeholder="请输入邮箱"
              required
            />
          </div>
        </div>
        
        <div class="form-group">
          <label for="password" class="form-label">密码</label>
          <div class="input-wrapper">
            <i class="fas fa-lock input-icon"></i>
            <input
              id="password"
              v-model="registerForm.password"
              type="password"
              class="form-input"
              placeholder="请输入密码"
              required
            />
          </div>
        </div>
        
        <div class="form-group">
          <label for="confirmPassword" class="form-label">确认密码</label>
          <div class="input-wrapper">
            <i class="fas fa-lock input-icon"></i>
            <input
              id="confirmPassword"
              v-model="registerForm.confirmPassword"
              type="password"
              class="form-input"
              placeholder="请再次输入密码"
              required
            />
          </div>
        </div>
        
        <button
          type="submit"
          class="register-button"
          :disabled="loading"
        >
          <span v-if="!loading">注册</span>
          <span v-else>
            <i class="fas fa-spinner fa-spin"></i> 注册中...
          </span>
        </button>
      </form>
      
      <div class="register-footer">
        <p class="login-link">
          已有账户？ <a @click="goToLogin" class="login-link-text">立即登录</a>
        </p>
        <p class="copyright">© 2025 钢铁企业安全生产智能监管平台. 保留所有权利.</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Register',
  data() {
    return {
      registerForm: {
        username: '',
        email: '',
        password: '',
        confirmPassword: ''
      },
      loading: false
    }
  },
  methods: {
    handleRegister() {
      // 简单验证密码是否一致
      if (this.registerForm.password !== this.registerForm.confirmPassword) {
        alert('两次输入的密码不一致');
        return;
      }
      
      this.loading = true;
      
      // 模拟注册过程
      setTimeout(() => {
        // 保存用户信息到本地存储
        const userInfo = {
          name: this.registerForm.username,
          email: this.registerForm.email,
          token: 'mock-token-' + Date.now()
        };
        
        // 这里应该调用实际的注册API
        localStorage.setItem('userInfo', JSON.stringify(userInfo));
        localStorage.setItem('token', userInfo.token);
        
        // 注册成功后跳转到登录页面，并提示用户进行登录
        this.loading = false;
        this.$router.push('/login');
        this.$nextTick(() => {
          alert('注册成功，请进行登录');
        });
      }, 1000);
    },
    goToLogin() {
      this.$router.push('/login');
    }
  }
}
</script>

<style scoped>
.register-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  padding: 20px;
}

.register-box {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.register-header {
  padding: 30px;
  text-align: center;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: white;
}

.register-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 10px;
}

.register-subtitle {
  font-size: 16px;
  opacity: 0.9;
}

.register-form {
  padding: 30px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}

.form-input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  transition: border-color 0.3s;
  box-sizing: border-box;
}

.form-input:focus {
  outline: none;
  border-color: #1e3c72;
  box-shadow: 0 0 0 2px rgba(30, 60, 114, 0.2);
}

.register-button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.3s;
  margin-top: 10px;
}

.register-button:hover:not(:disabled) {
  opacity: 0.9;
}

.register-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.register-footer {
  padding: 20px;
  text-align: center;
  border-top: 1px solid #eee;
}

.login-link {
  margin-bottom: 15px;
  font-size: 14px;
  color: #666;
}

.login-link-text {
  color: #1e3c72;
  cursor: pointer;
  font-weight: 500;
  text-decoration: underline;
}

.copyright {
  font-size: 12px;
  color: #999;
}
</style>